from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from .api import auth, user, product, group_buy, orders
from .core.database import engine
from .models import user as user_model, store, product as product_model, group_buy_order, user_order, stored_value_card, consumption_record

# 创建数据库表
user_model.Base.metadata.create_all(bind=engine)

app = FastAPI(title="拼卡鸭API", version="1.0.0")

# 配置CORS
app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

# 注册路由
app.include_router(auth.router, prefix="/api")
app.include_router(user.router)
app.include_router(product.router)
app.include_router(group_buy.router)
app.include_router(orders.router)

@app.get("/")
async def root():
    return {"message": "拼卡鸭API服务运行中"}
